package cn.sdormitory.controller.basedata;

import cn.sdormitory.basedata.entity.BCourse;
import cn.sdormitory.basedata.service.BCourseService;
import cn.sdormitory.basedata.vo.CourseQueryVo;
import cn.sdormitory.common.api.CommonPage;
import cn.sdormitory.common.api.CommonResult;
import cn.sdormitory.sys.entity.SysDictDetail;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "Basedata-course=> 课程")
@RequestMapping("/basedata/bcourse")
public class BCourseController {

    @Autowired
    BCourseService bCourseService;

    @PostMapping("/findPageList")
    public CommonResult findPageList(@RequestBody CourseQueryVo queryVo){
        IPage<BCourse> list = bCourseService.findPageList(queryVo);
        return CommonResult.success(CommonPage.restPage(list));
    }

    @PostMapping("/createOrUpdateCourse")
    public CommonResult createOrUpdateCourse(@RequestBody BCourse bCourse){
        int flag = bCourseService.createOrUpdateCourse(bCourse);
        if(flag > 0){
            return CommonResult.success();
        }else {
            return CommonResult.failed();
        }
    }

    @DeleteMapping("/deleteById/{id}")
    public CommonResult deleteById(@PathVariable("id") Long id){
        bCourseService.deleteByIds(id);
        return CommonResult.success();
    }

    @GetMapping("/findAllCourseTerm")
    public CommonResult findAllCourseTerm(){
        List<SysDictDetail> list = bCourseService.findAllCourseTerm();
        return CommonResult.success(list);
    }

    @GetMapping("/findAllCourse")
    public CommonResult findAllCourse(){
        List<BCourse> list = bCourseService.findAllCourse();
        return CommonResult.success(list);
    }
}
